<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="inputlib" uri="/WEB-INF/taglibs-input.tld" %>
<%@ page import="tau.dimes.web.UserFiles"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<%@page import="java.util.*"%>
<%@page import="tau.dimes.config.db.DatabaseConfiguration"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link type="text/css" rel="stylesheet" href="<%=application.getContextPath()%>/styles/jquery-ui.css" />
<link type="text/css" rel="stylesheet" href="<%=application.getContextPath()%>/styles/queryDB.css" />
<title>Dimes - Query DB</title>
</head>
<body>
<%@ include file="Header.jsp"%>
<script type="text/javascript" src="<%=root%>/script/jquery-ui.min.js"></script>
<script type="text/javascript" src="<%=root%>/script/jquery.simpleautogrow.js"></script>
<script type="text/javascript" src="<%=root%>/script/queryDB.js"></script>
<div id="divPreviewQuery">Select a server: <select id="serverName">
	<%
		Set<String> serverNames = DatabaseConfiguration.getInstance().getServerNames();
		for (String serverName : serverNames)
		{
	%>
	<option value="<%=serverName%>"><%=serverName%></option>
	<%
		}
	%>
</select> Preview Rows: <select id="previewRows">
	<option value="5">5</option>
	<option value="10">10</option>
	<option value="25">25</option>
	<option value="50" selected="selected">50</option>
</select> Saved Query: <select id="ddlQueryName" name="ddlQueryName">
				<%
					if (login.isLoggedIn())
					{
						UserFiles userFiles = new UserFiles(login.getUsername(), application);
						String[] files = userFiles.listFiles(".query.xml");
						if (files.length > 0)
						{
				%>
					<option value="">Select to load...</option>
				<%
						}
						else
						{
				%>
							<option value="">No saved queries</option>
				<%
						}
						for (String file : files)
						{
				%>
					<option value="<%= file %>"><%= file.substring(0, file.length() - 10) %></option>
				<%
						}
					}
				%>
</select>
<input type="hidden" id="selectedQuery" value=""/>				 
<br />
Enter your query here: <br />
<div id="divQuery"><textarea id="query"></textarea></div>
<button id="btnPreviewQuery">Preview Query</button>
<button id="btnNextToIpGeo" disabled="disabled">Next</button>
</div>
<div id="divIpGeo" style="display: none;">
	<table cellpadding="1px" cellspacing="1px">
		<tr>
			<td><label>Select IP column:</label></td>
			<td><select id="ipColumn"></select></td>
 		</tr>
 	</table>
<button id="btnBackToPreviewQuery">Back</button>
<button id="btnPreviewIpGeo">Preview IpGeo</button>
<button id="btnNextToFieldSelect">Next</button>
</div>
<div id="divFieldSelect" style="display: none;">
	<table cellpadding="1px" cellspacing="1px">
		<tr>
			<td><label>Trace Column:</label></td>
			<td><select id="traceColumn"></select></td>
 		</tr>
 		<tr>
 			<td><label>Query Name:</label></td>
 			<td><input id="queryFilename" type="text"></input></td>
 		</tr>
 		<tr>
 			<td><label>Results File Name:</label></td>
 			<td><input id="resultsFilename" type="text"></input></td>
 		</tr>
 		<tr>
 			<td><label>Maximum Rows:</label></td>
 			<td><input id="maxRows" type="text"></input></td>
 		</tr>
 	</table>
<button id="btnBackToIpGeo">Back</button>
<button id="btnSaveQuery">Save Query</button>
<button id="btnSaveResults">Save Results</button>
</div>
<div id="divQueryResults"></div>
<div id="divAjaxOverlay">
<table>
	<tbody>
		<tr>
			<td>
				<img id="loadingImage" src="<%=root%>/images/loading.gif">
				<div id="progressBar"></div>
			</td>
		</tr>
	</tbody>
</table>
</div>
</body>
</html>